package hlhj.fhp.supreme.customview

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import hlhj.fhp.supreme.Contents
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.utils.MyUtils
import kotlinx.android.synthetic.main.his_pop.view.*
import java.util.ArrayList

/**
 * Created by Administrator on 2018\4\20 0020.
 * type-1年 2月
 */
class HisPop(private val context: Context,private val type:Int,private val listener:OnTimeClickListener) :PopupWindow(){
    private lateinit var year:String
    private lateinit var month:String
    private  var num:Int=0
    private val timeDatas=ArrayList<Int>()
    private lateinit var adp:BaseQuickAdapter<Int,BaseViewHolder>
    init {

        initPop()
    }

    private fun initPop() {
        this.animationStyle= R.style.class_pop_style
        this.width= LinearLayout.LayoutParams.WRAP_CONTENT
        this.height= LinearLayout.LayoutParams.WRAP_CONTENT

        contentView=LayoutInflater.from(context).inflate(R.layout.his_pop,null)
        adp=object :BaseQuickAdapter<Int,BaseViewHolder>(R.layout.his_pop_item,timeDatas){
            override fun convert(helper: BaseViewHolder?, item: Int?) {
                helper?.setText(R.id.tv,item?.toString())
            }
        }
        contentView.listView.adapter=adp
        contentView.listView.layoutManager=LinearLayoutManager(context,LinearLayout.VERTICAL,false)
        year=MyUtils.getYear()
        month=MyUtils.getMonth()

        when(type){
            1->{
                var y = year.toInt()
                for (i in 0..10){
                    timeDatas.add(y)
                    y--
                }
                adp.notifyLoadMoreToLoading()
            }
            2->{
                timeDatas.add(1)
                timeDatas.add(2)
                timeDatas.add(3)
                timeDatas.add(4)
                timeDatas.add(5)
                timeDatas.add(6)
                timeDatas.add(7)
                timeDatas.add(8)
                timeDatas.add(9)
                timeDatas.add(10)
                timeDatas.add(11)
                timeDatas.add(12)
                adp.notifyDataSetChanged()
            }
        }
        adp.setOnItemClickListener { adapter, view, position ->
            listener.onTimeClick(timeDatas[position])
            dismiss()
        }
    }
    interface OnTimeClickListener{
        fun onTimeClick(i:Int)
    }
}